namespace Code1
{
	using System;
	using System.Text ;
	using System.Web;
	using System.Data;
    using CodeFx.Web;
    using MySql.Data.MySqlClient;

	public partial class MailDAL: DALBase
	{
		/// <summary>
		/// Enumeration de tous les champs de mail
		/// <summary>
		public enum Fields 
		{ 
			#region Enumeration de tous les champs de mail
IdMail,
FromMail,
ToMail,
Sujet,
Body,
Date
			#endregion
		}
	
		#region Private Properties mail
		/// <summary>
		/// Champ IdMail de la table mail
		/// </summary>
		/// <remarks>Membre de la cle primaire. </remarks>
		private uint _IdMail;

		/// <summary>
		/// Champ FromMail de la table mail
		/// </summary>
		/// <remarks>Membre Non Nullable. </remarks>
		private string _FromMail = String.Empty;

		/// <summary>
		/// Champ ToMail de la table mail
		/// </summary>
		/// <remarks>Membre Non Nullable. Membre d'une cle etrangere. </remarks>
		private string _ToMail = String.Empty;

		/// <summary>
		/// Champ Sujet de la table mail
		/// </summary>
		/// <remarks>Membre Non Nullable. </remarks>
		private string _Sujet = String.Empty;

		/// <summary>
		/// Champ Body de la table mail
		/// </summary>
		/// <remarks>Membre Non Nullable. </remarks>
		private string _Body;

		/// <summary>
		/// Champ Date de la table mail
		/// </summary>
		private DateTime _Date;

		#endregion
		
		#region Public Properties
		
		public uint IdMail
		{
			get {return this._IdMail;}
			set {
					if ( this._IdMail != value)
					{
						this.IsTouched = (this._IdMail != value);
						this._IdMail = value;
					}
				}
		}

		public string FromMail
		{
			get {return this._FromMail;}
			set {
					if ( this._FromMail != value)
					{
						this.IsTouched = (this._FromMail != value);
						this._FromMail = value;
					}
				}
		}

		public string ToMail
		{
			get {return this._ToMail;}
			set {
					if ( this._ToMail != value)
					{
						this.IsTouched = (this._ToMail != value);
						this._ToMail = value;
					}
				}
		}

		public string Sujet
		{
			get {return this._Sujet;}
			set {
					if ( this._Sujet != value)
					{
						this.IsTouched = (this._Sujet != value);
						this._Sujet = value;
					}
				}
		}

		public string Body
		{
			get {return this._Body;}
			set {
					if ( this._Body != value)
					{
						this.IsTouched = (this._Body != value);
						this._Body = value;
					}
				}
		}

		public DateTime Date
		{
			get {return this._Date;}
			set {
					if ( this._Date != value)
					{
						this.IsTouched = (this._Date != value);
						this._Date = value;
					}
				}
		}
		
		public string Key
        {
			get
			{
        	   	return this._IdMail.ToString();
        	}
		}
		#endregion
		
		#region Override Methods
		public void Clone(MailDAL dataObject)
        {
            if (dataObject == null)
                throw new ArgumentNullException("dataObject");
            	this._FromMail = dataObject.FromMail;
            	this._ToMail = dataObject.ToMail;
            	this._Sujet = dataObject.Sujet;
            	this._Body = dataObject.Body;
            	this._Date = dataObject.Date;
        }
		
       	public override sealed string ToString()
        {
            StringBuilder Text = new StringBuilder( this.GetType().FullName );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "IdMail", this.IdMail, "PK " );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "FromMail", this.FromMail, "" );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "ToMail", this.ToMail, "FK " );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "Sujet", this.Sujet, "" );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "Body", this.Body, "" );
			Text.AppendFormat( "\r\n \t{0} {2}: {1}", "Date", this.Date, "" );
			return Text.ToString();
        }
		
		public override sealed void Read(IDataReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");
            base.Read(reader);
			try{
			    MySqlDataReader myreader = (MySqlDataReader)reader;
                if (!myreader.IsDBNull((int)MailDAL.Fields.IdMail))
                this._IdMail= myreader.GetUInt32((int)MailDAL.Fields.IdMail);
                if (!myreader.IsDBNull((int)MailDAL.Fields.FromMail))
                this._FromMail= myreader.GetString((int)MailDAL.Fields.FromMail);
                if (!myreader.IsDBNull((int)MailDAL.Fields.ToMail))
                this._ToMail= myreader.GetString((int)MailDAL.Fields.ToMail);
                if (!myreader.IsDBNull((int)MailDAL.Fields.Sujet))
                this._Sujet= myreader.GetString((int)MailDAL.Fields.Sujet);
                if (!myreader.IsDBNull((int)MailDAL.Fields.Body))
                this._Body= myreader.GetString((int)MailDAL.Fields.Body);
                if (!myreader.IsDBNull((int)MailDAL.Fields.Date))
                this._Date= myreader.GetDateTime((int)MailDAL.Fields.Date);
			}
			catch (Exception ex)
			{
				throw new DALException(ex.InnerException);
			}
        }

        public override sealed void Write(IDbCommand cmd)
        {
			if (cmd == null)
                throw new ArgumentNullException("cmd");
            base.Write(cmd);
			try
			{
                cmd.Parameters.Add(new MySqlParameter("?IdMail", this._IdMail));
                cmd.Parameters.Add(new MySqlParameter("?FromMail", this._FromMail));
                cmd.Parameters.Add(new MySqlParameter("?ToMail", this._ToMail));
                cmd.Parameters.Add(new MySqlParameter("?Sujet", this._Sujet));
                cmd.Parameters.Add(new MySqlParameter("?Body", this._Body));
                cmd.Parameters.Add(new MySqlParameter("?Date", this._Date));
			}
			catch (Exception ex)
			{
				throw new DALException(ex.InnerException);
			}
        }

		public override sealed void WriteId(IDbCommand cmd)
        {
            if (cmd == null)
                throw new ArgumentNullException("cmd");
            base.WriteId(cmd);
            cmd.Parameters.Add(new MySqlParameter("?IdMail", this._IdMail));
        }
        #endregion
				
	}
}
